﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;

namespace DNFImagePacks2Manager.Helpers
{
    public static class EnumHelper
    {
        public static string GetDescription<TEnum>(this TEnum enumValue)
        where TEnum : struct, Enum
        {
            var attribute = enumValue.GetType()
                .GetMember(enumValue.ToString())[0]
                .GetCustomAttribute<DescriptionAttribute>();

            return attribute?.Description ?? enumValue.ToString();
        }

        public static List<string> GetAllDescriptions<TEnum>()
            where TEnum : struct, Enum
        {
            return Enum.GetValues<TEnum>()
                .Select(enumValue => enumValue.GetDescription())
                .ToList();
        }
    }
}
